import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

//没有权限要求的基本页 都可以进入
export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: {
      title: '登录'
    }

  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 全屏可视化
  {
    path: '/fullScreen',
    component: () => import('@/views/fullScreen'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    redirect: '/dashboard',
    component: Layout,
    hidden: false,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        hidden: false,
        meta: {
          title: '首页',
          icon: 'home',
          show: false
        }
      },
    ]
  },
  // 区域
  {
    path: `/orz`,
    component: Layout,
    hidden: false,
    children: [
      {
        path: 'orzManger',
        component: () => import('@/views/orz/index'),
        hidden: false,
        meta: {
          title: '区域管理',
          show: true,
          icon: 'orz',
        }
      }
    ]

  },

    // 分组管理
    {
      path: `/group`,
      component: Layout,
      hidden: false,
      children: [
        {
          path: 'groupManger',
          component: () => import('@/views/group/index'),
          hidden: false,
          meta: {
            title: '分组管理',
            show: true,
            icon: 'group',
          }
        }
      ]
  
    },

  // 个人中心
  {
    path: `/user`,
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'userManger',
        component: () => import('@/views/user/index'),
        hidden: true,
        meta: {
          title: '个人中心',
          show: false,
        }
      }
    ]

  },
  // 设备管理
  {
    path: `/device`,
    component: Layout,
    hidden: false,
    children: [
      {
        path: 'deviceManger',
        component: () => import('@/views/device/index'),
        hidden: false,
        meta: {
          title: '设备管理',
          show: true,
          icon: 'equipment',
        }
      }
    ]

  },
  // 银行卡
  {
    path: `/card`,
    component: Layout,
    hidden: false,
    children: [
      {
        path: 'cardManger',
        component: () => import('@/views/card/index'),
        hidden: false,
        meta: {
          title: '账户管理',
          show: true,
          icon: 'card',
        }
      },
      {
        path: 'cardNo',
        component: () => import('@/views/cardNo/index'),
        hidden: true,
        meta: {
          title: '添加银行卡',
          show: false,
          icon: 'card',
        }
      },
      {
        path: 'publicCard',
        component: () => import('@/views/publicCard/index'),
        hidden: true,
        meta: {
          title: '添加对公账户',
          show: false,
          icon: 'card',
        }
      }
    ]

  },
// 租币
  {
    path: `/money`,
    component: Layout,
    hidden: false,
    children: [
      {
        path: 'moneyManger',
        component: () => import('@/views/money/index'),
        hidden: false,
        meta: {
          title: '租币管理',
          show: true,
          icon: 'money',
        }
      }
    ]

  },
  // 报表
  {
    path: `/record`,
    component: Layout,
    hidden: false,
    meta: {
      title: '统计报表',
      show: true,
      icon: 'statement',
    },
    children: [
      {
        path: 'chargeRecord',
        component: () => import('@/views/chargeRecord/index'),
        hidden: false,
        meta: {
          title: '充值报表',
          show: true,
          icon: 'chargeState',
        }
      },
      {
        path: 'energyRecord',
        component: () => import('@/views/energyRecord/index'),
        hidden: false,
        meta: {
          title: '能耗报表',
          show: true,
          icon: 'energyState',
        }
      },
      {
        path: 'rentRecord',
        component: () => import('@/views/rentRecord/index'),
        hidden: false,
        meta: {
          title: '租金记录',
          show: true,
          icon: 'rent',
        }
      }
    ]

  },
  { path: '*', redirect: '/404', hidden: true },

]

// 根据权限显示的路由
export const asyncRoutes = [
  // 404 页面必须放置在最后一个页面

]


const createRouter = () => new Router({
  mode: 'hash', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
